<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo  Q::ini('appini/app_title')." ". Q::ini('appini/version');?></title>
<link href="css/default.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="js/jquery-easyui/themes/default/easyui.css"/>
<link rel="stylesheet" type="text/css" href="js/jquery-easyui/themes/icon.css"/>
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery-easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="js/jquery-easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>

<script language="javascript">
function newcategory(){  
    $('#dlg').dialog('open').dialog('setTitle','添加商品类别');  
    $('#fm').form('clear');  
	$("#parent").combotree("reload");	
    url = '<?=url("category/new")?>';  
} 

function editcategory(){
	var row = $('#tCategory').datagrid('getSelected');  
	$("#parent").combotree("reload");	
    if (row){  
        $('#dlg').dialog('open').dialog('setTitle','编辑商品类别');  
        $('#fm').form('load',row);  
		url = '<?=url("category/update")?>';
    } 
	else{
		$.messager.show({
			'title': "提示",
			'msg': "请选择要编辑的记录."	
		});	
	} 		
}

function savecategory(){  
	$('#fm').form('submit',{  
		url: url,  
		onSubmit: function(){  
			return $(this).form('validate');  
		},  
		success: function(result){  
			var result = eval('('+result+')');  
			if (result.errorMsg){  
				$.messager.show({  
					title: '出错了',  
					msg: result.errorMsg  
				});  
			} else {  
				$('#dlg').dialog('close');      // close the dialog  
				$('#tCategory').treegrid('reload');    // reload the user data  
			}  
		}  
	});  
}  

function destroycategory(){  
    var row = $('#tCategory').datagrid('getSelected');  
    if (row){  
        $.messager.confirm('确认','您确认要删除该记录吗?',function(r){  
            if (r){  
                $.post('<?=url("category/destroy")?>',{id:row.category_id},function(result){  
                    if (result.success){  
                        $('#tCategory').treegrid('reload');    // reload the user data  
                    } else {  
                        $.messager.show({   // show error message  
                            title: '出错了',  
                            msg: result.errorMsg  
                        });  
                    }  
                },'json');  
            }  
        });  
    }
	else{
		$.messager.show({   // show error message  
			title: '提示',  
			msg: "请选择要删除的记录."
		});  	
	}  
}


</script>
</head>

<body class="easyui-layout" style="overflow-y: hidden" scroll="no">
    
<div region="center" style="width: 500px; height: 300px; padding: 1px;overflow-y: hidden">
    <table id="tCategory" title="商品类别" class="easyui-treegrid" toolbar="#toolbar" data-options="url: '<?=url("category/list")?>',rownumbers: true,idField: 'category_id',treeField: 'name'" iconCls="icon-save" fit="true">  
        <thead>  
            <tr>  
                <th field="code" width="100">类别代码</th>  
                <th field="name" width="260">类别名称</th> 
            </tr>  
        </thead>  
    </table>  
        <div id="toolbar">  
            <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newcategory()">新增</a>  
            <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editcategory()">编辑</a>  
            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroycategory()">删除</a>  
    	</div>  
    </div>
	<div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px" closed="true" buttons="#dlg-buttons"  modal="true">  
        <div class="ftitle">详细信息</div>  
        <form id="fm" method="post">  
            <div class="fitem">  
                <label>类别编码:</label>  
                <input name="code" id="code" class="easyui-validatebox" required="true" style="width:200px;">  
            </div>  
            <div class="fitem">  
                <label>类别名称:</label>  
                <input name="name" id="name" class="easyui-validatebox" required="true" style="width:200px;">  
            </div>  
            <div class="fitem">  
                <label>所属类别:</label>  
                <input class="easyui-combotree" valueField = 'category_id' textField = 'name' data-options="url:'<?=url('category/list',array('comobotree'=>true))?>',required:true" id="parent" name="parent" style="width:202px;"/> 
            </div>
            <input name="category_id" id="category_id" type="hidden"  />
        </form>  
    </div>  
    <div id="dlg-buttons">  
        <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="savecategory()">保存</a>  
        <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>  
    </div>       
</body>
</html>